package com.demo.controller;

import com.demo.common.AppResult;
import com.demo.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author quan
 * @Description TODO
 * @Date 2023/8/8 12:31
 */



@Api(tags = "测试接口")
@Slf4j
@RequestMapping("/test")
// Controller注解，返回的对象⽤JSON形式表⽰
@RestController
//表示在Body中返回数据
public class TestController {
    @ApiOperation("hello测试")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot...";
    }

    //测试异常
    @ApiOperation("测试异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }
    @ApiOperation("自定义异常测试")
    @GetMapping("/applicationException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException...");
    }

    @ApiOperation("hello测试  带参")
    @GetMapping("/helloByName")
//    @ApiImplicitParam()
    public AppResult helloByName(@ApiParam("名字") String name){
        return AppResult.success("你好,"+name);
    }
}

